package com.edwin.websitebe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.edwin.websitebe.mapper.SampleMapper;
import com.edwin.websitebe.model.Knowledge;
import com.edwin.websitebe.model.News;
import com.edwin.websitebe.model.Sample;
import com.edwin.websitebe.service.SampleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class SampleServiceImpl extends ServiceImpl<SampleMapper, Sample> implements SampleService {
    @Override
    public Page<Sample> pageList(Sample sample) {
        LambdaQueryWrapper<Sample> wrapper = new QueryWrapper<Sample>().lambda()
                .like(StringUtils.isNotEmpty(sample.getSampleTitle()), Sample::getSampleTitle, sample.getSampleTitle())
                .orderByAsc(Sample::getSort)
                .orderByDesc(Sample::getCreateTime);
        return this.page(Page.of(sample.getPage(), sample.getPageSize()), wrapper);
    }
}
